﻿<!-- Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. -->
<Page
    x:Name="pageRoot"
    x:Class="Weathr.LocationsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Weathr"
    xmlns:common="using:Weathr.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <!-- Collection of items displayed by this page -->
        <CollectionViewSource x:Name="groupsViewSource" Source="{Binding Groups}" IsSourceGrouped="True" ItemsPath="Items"/>

        <!-- This storyboard darkens the background color. We lighten the background color when we navigate from the main page to this one. -->
        <Storyboard x:Name="DarkenBackground" Duration="0:0:1">
            <ColorAnimation EnableDependentAnimation="True" 
                        Storyboard.TargetProperty="(UIElement.Background).(SolidColorBrush.Color)"
                        Storyboard.TargetName="RootElement"
                        Duration="0:0:1" From="#00000000" To="#88000000"/>
        </Storyboard>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid x:Name="RootElement" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <SemanticZoom x:Name="semanticZoom" VerticalAlignment="Center" Grid.RowSpan="2" ViewChangeStarted="semanticZoom_ViewChangeStarted">

            <SemanticZoom.ZoomedOutView>
                <GridView Foreground="White"
                  ScrollViewer.IsHorizontalScrollChainingEnabled="False">
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock
                        Text="{Binding Group.Title}"
                        FontFamily="Segoe UI Light"
                        FontSize="24"/>
                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid ItemWidth="75" ItemHeight="75" MaximumRowsOrColumns="2" 
                              VerticalChildrenAlignment="Center" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemContainerStyle>
                        <Style TargetType="GridViewItem">
                            <Setter Property="Margin" Value="4" />
                            <Setter Property="Padding" Value="10" />
                            <Setter Property="Background" Value="Green"/>
                            <Setter Property="BorderThickness" Value="1" />
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                            <Setter Property="VerticalContentAlignment" Value="Bottom" />
                        </Style>
                    </GridView.ItemContainerStyle>
                </GridView>
            </SemanticZoom.ZoomedOutView>

            <SemanticZoom.ZoomedInView>
                <!-- Horizontal scrolling grid -->
                <GridView
                    x:Name="itemGridView"
                    ItemsSource="{Binding Source={StaticResource groupsViewSource}}"
                    VerticalAlignment="Center"
                    ScrollViewer.IsHorizontalScrollChainingEnabled="False"
                    SelectionMode="Multiple"
                    IsSwipeEnabled="True"
                    SelectionChanged="itemGridView_SelectionChanged">
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Left" Width="125" Height="125">
                                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                                    <Image Source="{Binding Path=Item.ThumbnailImagePath}" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" AutomationProperties.Name="{Binding Title}" ImageFailed="Image_ImageFailed"/>
                                </Border>
                                <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                                    <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" Height="30" Margin="15,0,15,0" FontWeight="SemiBold"/>
                                    <TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10" FontSize="12"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </GridView.ItemTemplate>

                    <GridView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Text='{Binding Title}' Foreground="Gray" 
                                       Margin="5" FontSize="18" FontFamily="Segoe UI Light" />
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="3" />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </GridView.GroupStyle>

                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <Button Visibility="Collapsed"/>
                </GridView>
            </SemanticZoom.ZoomedInView>

        </SemanticZoom>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                       IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
    </Grid>

    <Page.BottomAppBar>
        <CommandBar x:Name="BottomCommandBar"
            x:Uid="CommandBar"
            Padding="10,0,10,0"
            IsSticky="True">
            <AppBarButton
                        Icon="Delete"
                        Label="Delete Selected"
                        Click="DeleteSelection_Click"
                        IsEnabled="{Binding HasSelection}"/>

            <AppBarButton
                        x:Name="ClearSelectionAppBarButton"
                        Icon="ClearSelection"
                        Label="Clear Selection"
                        Click="ClearSelection_Click"
                        IsEnabled="{Binding HasSelection}"/>

            <AppBarButton
                        Icon="Document"
                        Label="Reset"
                        Click="Reset_Click"/>
        </CommandBar>

    </Page.BottomAppBar>
</Page>
